#include "process.h"    
#include <string.h>    
#include <unistd.h>    
    
#define SIZE 101    
#define STYLE '#'    
    
// v2：根据进度，动态刷新一次进度条    
void FlushProcess(const char* tips,double total,double current)    
{    
    const char* label = "|/-\\";    
    int len = strlen(label);    
    static int index = 0;    
    
    char buffer[SIZE];    
    memset(buffer,0,sizeof(buffer));    
    
    double rate = (current*100.0)/total;    
    int num = (int)rate;    
    
    int i = 0;    
    for(; i < num; i++)    
    {    
        buffer[i]=STYLE;    
    }    
    
    printf("%s...[%-100s][%.1lf%%][%c]\r",tips,buffer,rate,label[index++]);                                                                                                                               
    fflush(stdout);    
    index%=len;    
}    
    
// v1：展示进度条基本功能    
void process()    
{    
    int rate=0;    
    char buffer[SIZE];    
    memset(buffer,0,sizeof(buffer));    
    const char* label = "|/-\\";    
    int len = strlen(label);    
    
    while(rate<=100)
    {    
        printf("[%-100s][%d%%][%c]\r",buffer,rate,label[rate%len]);
        fflush(stdout);
        buffer[rate]=STYLE;
        ++rate;
        usleep(50000);
    }
    printf("\n");
}